split()

Read(22) Label: string, delimiter, sequence,

Here’s how to use split() function.

s.split()

Description:

Split a string into a sequence using the delimiter.

Syntax:

s.split(d)

Note:

The function splits string s with delimiter d into a sequence and returns a sequence of strings.

Parameter:

s

A string to be split.

d

The delimiter; support splitting a string into multiple characters; if omitted, split the string into a sequence of single characters.

Option:

@p

Parse members into corresponding data types after the splitting. That is to say, numbers shall be handled as numeric values, members enclosed by [] shall be recognized as sequences, dates like 2001-01-01 shall be treated as date type data, and so on. The parsing of the sign [] also involves the same handling of a sub-sequence. Parentheses matching will be handled.

@1

Split string into two parts at the position of the first d found.

@b

Won’t handle quotation marks matching and parentheses matching.

@t

Perform trim operation to remove blank characters from both ends of each string member and split the original string according to continuous blank characters when d is omitted.

@c

Split the string using the comma.

@r

Treat parameter d as a regular expression.

@n

Spit a string using the carriage return \n, and split each substring according to the other options if there are any, and return a sequence of sequences.

@z

Split string into two parts at the position of the last d found.

@g

Treat angle brackets <> as parentheses; by default, they are left as is.

@y

Use this option when parameter d is an array. In the array, each member is regarded as representing the length of the corresponding segment of characters, and the function splits the source string according to the specified lengths. When a member is a negative number, skip this number of characters.

Return value:

Sequence

Example:

 

A

 

1

="1,[a,b],(2,c),'5,6'"

2

=A1.split@c()

 

Comma is used to split the string.

3

=A1.split@c1()

Split the string at the position of the first delimiter.

4

=A1.split@cb()

Use comma as the delimiter and won’t handle quotation marks matching and parentheses matching.

5

="a:b:c".split(":")

Use colon as the delimiter.

6

=A1.split@cp()

Use comma as the delimiter and parse each split member into its proper data type.

7

="1,[a,b],(2,c),  abc  ,'5,6'".split@ct()

Remove blank characters from both ends of "abc".

8

="1,[a,b],(2,c),  abc  ,'5,6'".split@t()

Split the string according to continuous blank characters since d is omitted.

9

=A1.split()

Split the string into a sequence of single characters since d is omitted.

10

="a:;b:;c".split(":;")

["a","b","c"].

11

="a1b2c".split@r("(\\d)")

12

="s,a,y\ngood,morning".split@nc()

Split the string into [s,a,y] and [good,moring] and then split each substring by comma.

13

="a:b:c:d:e".split@z(":")

Use @z option to split the string into two segments at the position of the last delimiter:

14

="1,[a,b],<2,3>,'5,6'".split@gc()

Use @g option to treat angle brackets <> as parentheses:

15

="1,2,'3',4%5".split@y([1,3,-2,4])

@y option enables splitting the source array according to the specified lengths, where -2 means skipping two characters: